package kuang.juc.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

//Executors 工具类、三大方法
public class Demo01 {
    public static void main(String[] args) {
        //单一线程
        //ExecutorService threadPool = Executors.newSingleThreadExecutor();
        //指定数量
        //ExecutorService threadPool = Executors.newFixedThreadPool(5);
        //可变的
        ExecutorService threadPool = Executors.newCachedThreadPool();

        for (int i = 0; i < 20; i++) {
            //通过线程池开启
            threadPool.execute(()->{
                System.out.println(Thread.currentThread().getName());
            });
        }

        //关闭线程池
        threadPool.shutdown();


    }
}
